import type { Api } from '@/typings/request'
import { ERROR_STATUS } from '@/utils/request/constant'

/**
 * 根据错误码，生成错误结果
 * @param statusCode
 */
export function transformResultByErrorStatus(
    statusCode: Api.ErrorStatus,
    data: any = null
): Api.Result {
    const error: Api.Error = {
        type: 'axios',
        code: statusCode,
        msg: ERROR_STATUS[statusCode]
    }
    return {
        error,
        result: data
    }
}
/**
 * 根据错误码，生成错误结果
 * @param statusCode
 */
export function transformResultByBackendError(
    code: string | number,
    msg: string,
    data: any
): Api.Result {
    const error: Api.Error = {
        type: 'backend',
        code,
        msg
    }
    return {
        error,
        result: data
    }
}
